<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
    <style type="text/css">
		.item{
			width: 95px;
			display: inline-block;
			margin-left: 5px;
		}
	</style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:30%;">
                <span class="item">用户名称(模糊)：</span><input id="s_name" class="mini-textbox" emptyText="请输入用户名称" style="width:150px;" />
            </td>
            <td style="width:30%;">
            	<span class="item">状态(精确)：</span>
            	<div id="s_status" emptyText="请选择..." class="mini-combobox" style="width:150px;"  popupWidth="165" textField="keyValue" valueField="keyName" 
				    url="dictionary_key_val_view.do?typeName=JOB_STATUS" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="状态(精确)" field="keyValue"></div>
				    </div>
				</div>
			</td>
			<td style="width:30%;">
            	<span class="item">登录名称(精确)：</span><input id="s_username" class="mini-textbox" emptyText="请输入登录名称" style="width:150px;"/>
            </td>
            <td></td>
        </tr>
        <tr>
        	<td style="width:30%;">
        		<span class="item">部门(精确)：</span>
        		<div id="s_depts" emptyText="请选择..." class="mini-combobox" style="width:150px;" popupWidth="165" textField="keyValue" valueField="keyName" 
				    url="dictionary_key_val_view.do?typeName=DEPT_TYPE" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="部门(精确)" field="keyValue"></div>
				    </div>
				</div>
			</td>
			<td style="width:30%;">	
        		<span class="item">组(精确)：</span>
				<div id="s_groups" emptyText="请选择..." class="mini-combobox" style="width:150px;"  popupWidth="165" textField="name" valueField="id" 
				    url="user_group_view.do" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="组(精确)" field="name"></div>
				    </div>
				</div>
        	</td>
        	<td></td>
            <td style="white-space:nowrap;">
				<a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            </td>   
        </tr>
    </table>           
</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
		        <td style="width:100%;">
				<sec:authorize url='/medical_user_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	           	</sec:authorize>
	            <sec:authorize url='/medical_user_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
                </sec:authorize>
                <sec:authorize url='/meidcal_user_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">批量删除</a>
               	</sec:authorize>
                <sec:authorize url='/export_current_data.do'>       
                    <a class="mini-button" iconCls="icon-download" onclick="exportCurrentData()">导出当前</a>
                    <a class="mini-button" iconCls="icon-download" onclick="exportAllData()">导出所有</a>
                </sec:authorize>
                <sec:authorize url='/download_user_template.do'>
                    <a class="mini-button" iconCls="icon-download" onclick="download()">下载模板</a>
                </sec:authorize>
                <sec:authorize url='/medical_user_import_add.do'>
                    <a class="mini-button" iconCls="icon-upload" onclick="exportInData()">批量导入</a>
                </sec:authorize>
	            </td>
	        </tr>
	    </table>           
	</div>
	
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid" idField="id" pageSize="20"
		url="user_list_view.do" style="width:100%;height:100%;" allowCellSelect="true" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn" headerAlign="center">#</div>
			<div type="checkcolumn" headerAlign="center"></div>
			<div field="name" width="100" headerAlign="center" align="center">姓名</div>
			<div field="username" width="100" headerAlign="center" align="center">登录名</div>
			<div field="deptName" width="120" headerAlign="center" align="center">部门</div>
			<div field="groupName" width="100" headerAlign="center" align="center">组</div>
			<div field="status" width="80" headerAlign="center" align="center">状态</div>
			<div field="lineStatus" width="80" headerAlign="center" align="center">在线状态</div>
			<div field="platformName" width="120" headerAlign="center" align="center">中心</div>
			<div field="createTime" width="140" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center" align="center" allowSort="true">注册时间</div>
			<div field="lastLoginTime" width="140" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center" allowSort="true" align="center">最后活动时间</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.load();
	
	//查询
	function search() {
	    var username = mini.get("s_username").getValue();
	    var name = mini.get("s_name").getValue();
	    var deptType = mini.get("s_depts").getValue();
	    var groupIds = mini.get("s_groups").getValue();
	    var status = mini.get("s_status").getValue();
	    grid.load({ username: username,
	    	name: name,
	    	deptType: deptType,
	    	groupId: groupIds,
	    	jobStatus: status
	    });
	}
	
	//添加
	function add() {
	    mini.open({
	        url: "medical_user_add.do",
	        allowResize:false,
	        title: "新增用户信息", width: 450, height: 430,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action: "new"};
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
	}
	
	//修改
	function edit() {
	    var row = grid.getSelecteds();
	    if (row.length == 1) {
	        mini.open({
	            url: "medical_user_edit.do",
	            allowResize:false,
	            title: "编辑用户信息", width: 450, height:500,
	            onload: function () {
	                var iframe = this.getIFrameEl();
	                var data = { action: "edit",row:row[0] };
	                iframe.contentWindow.SetData(data);
	            },
	            ondestroy: function (action) {
	            	if(action == 'succ'){
	            		mini.showMessageBox({
	                        title: "提示",
	                        showModal:false,
	                        iconCls: "mini-messagebox-info",
	                        message: "修改成功！",
	                        timeout: 3000,
	                        x: 'right',
	                        y: 'bottom'
	                    });
	                	grid.reload();
	            	}
	            }
	        });
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
	
	//删除
	function remove() {
		var userIds = '';
	    var rows = grid.getSelecteds();
	    if (rows.length > 0) {
	    	mini.confirm("确定删除选中记录？(删除用户将清空用户相关数据,确定进行此操作么？)", "删除",
               function (action) {
	    			if(action == 'ok'){
	    				var ids = [];
	    	            for (var i = 0, l = rows.length; i < l; i++) {
	    	                var r = rows[i];
	    	                ids.push(r.id);
	    	            }
	    	            userIds = ids.join(',');
						$.post('meidcal_user_del.do', {id: userIds}, function(data){
	    					if(data.success){
		    					mini.showMessageBox({
				                    title: "提示",
				                    showModal:false,
				                    iconCls: "mini-messagebox-info",
				                    message: "删除成功！",
				                    timeout: 3000,
				                    x: 'right',
				                    y: 'bottom',
				                });
	    						grid.load();
	    					}else{
	    						mini.alert("id不能为空，删除失败！");
	    					}
	   					}, "json");
	    			}
            	}
	    	);
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
	
	function onCloseClick(e) {
        var obj = e.sender;
        obj.setText("");
        obj.setValue("");
    }
	
	//导出全部
	function exportAllData(){
		location.href="export_all_data.do"; 
	}
	//导出当前页数据
	function exportCurrentData() {
		var data =grid.getData();
		var ids = [];
		$.each(data , function(){
	        ids.push(this.id);
	    });
		var id = ids.join(',');
		location.href="export_current_data.do?ids=" +id;
	}
	
	//下载模板
	function download(){
		location.href="download_user_template.do"; 
	}
	
	// 打开批量导入窗口
	function exportInData(){
    	mini.open({
	        url: "medical_user_import_add.do",
	        title: "批量导入员工信息", width: 320, height: 280,
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "导入成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
    }
</script>
</body>
</html>